package com.suning.sawp.service.impl.esb;

import java.util.List;

import org.springframework.stereotype.Service;

import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.suning.rsc.dto.responsedto.MbfResponse;
import com.suning.rsc.httpservice.annotation.EsbEIHttpWired;
import com.suning.sawp.dto.esb.OmsOrderDetailReq;
import com.suning.sawp.dto.esb.OmsOrderDetailReq.OmsOrderIdList;
import com.suning.sawp.dto.esb.OmsOrderDetailResp;
import com.suning.sawp.intf.esb.OmsOrderDetailEsbService;
import com.suning.sawp.intf.esb.OmsOrderDetailService;

/**
 * 
 * 功能描述： <br>
 * oms 订单详情接口
 *
 * @author 12072522
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
@Service
public class OmsOrderDetailServiceImpl implements OmsOrderDetailService {

    /**
     * 自营物流esb
     */
    private OmsOrderDetailEsbService omsOrderDetailEsbService;

    public OmsOrderDetailEsbService getOmsOrderDetailEsbService() {
        return omsOrderDetailEsbService;
    }

    @EsbEIHttpWired
    public void setOmsOrderDetailEsbService(OmsOrderDetailEsbService omsOrderDetailEsbService) {
        this.omsOrderDetailEsbService = omsOrderDetailEsbService;
    }

    @Override
    public OmsOrderDetailResp queryOrderDetails(List<String> omsOrdIds, String memberNo) {
        MbfResponse resp = null;
        OmsOrderDetailResp qresp = null;

        List<OmsOrderIdList> omsOrderIdLists = Lists.transform(omsOrdIds, new Function<String, OmsOrderIdList>() {
            @Override
            public OmsOrderIdList apply(String orderNo) {
                OmsOrderIdList temp = new OmsOrderIdList();
                temp.setOrderId(orderNo);
                return temp;
            }
        });
        OmsOrderDetailReq req = new OmsOrderDetailReq();
        req.setOrderIdLists(Lists.newArrayList(omsOrderIdLists));
        req.setMemberNo(memberNo);
        resp = omsOrderDetailEsbService.queryOrderDetails(req);
        if (null != resp && resp.isSucceed()) {
            qresp = (OmsOrderDetailResp) resp.getOutput().getMbfBody(OmsOrderDetailResp.class);
            if ("N".equalsIgnoreCase(qresp.getOperateFlag())) {
                // 详情查询失败,直接按null值处理
                qresp = null;
            }
        }
        return qresp;
    }

}
